﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace EducationManagementSystem.Admin
{
    public partial class ZhuRenManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {

            SqlConnection conn = DB.Conn();
            conn.Open();
            string sql = "select b.zhurenid,zhurenname,a.schoolname from school a,zhuren b where a.schoolid=b.schoolid  ";
            SqlCommand cmd = new SqlCommand(sql, conn);
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            sda.Fill(ds);
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("ZhuRendetails.aspx?Flag=Add");
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            Bind();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "de")
            {
                string zid = e.CommandArgument.ToString();
                SqlConnection conn = DB.Conn();
                conn.Open();
                string sql = "delete from zhuren where zhurenid='" + zid + "'  ";
                SqlCommand cmd = new SqlCommand(sql, conn);
                int a = cmd.ExecuteNonQuery();
                if (a > 0)
                {
                    this.Page.RegisterStartupScript(" ", "<script>alert(' 删除成功 '); </script> ");
                    Bind();
                }
                else
                {
                    this.Page.RegisterStartupScript(" ", "<script>alert(' 对不起，删除失败 '); </script> ");
                }
            }
            else 
            {
                string zid = e.CommandArgument.ToString();
                //传递修改的标志 跳转页面
                Response.Redirect("ZhuRendetails.aspx?Flag=xiu&ID=" + zid);
            }
        }
    }
}